package com.kongwg.java;


import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * @author kongwg
 * @create 2020-12-11 10:00
 */
public class CollectionTest {


    @Test
    public void test1(){


        Collection coll = new ArrayList();

        coll.add(123);
        coll.add(456);
        coll.add(new String("tom"));
        coll.add(false);
        coll.add(new Person("Jerry",20));
        coll.add(123);

        //contains():

        boolean contains = coll.contains(123);
        System.out.println(contains);
        boolean jetty = coll.contains(new Person("Jerry", 20));
        System.out.println(jetty);

        //containsAll()
        Collection coll1 = Arrays.asList(123,45);
        System.out.println(coll.containsAll(coll1));


    }
    @Test
    public void test2(){
        //3.remove(Object obj);
        Collection coll = new ArrayList();

        coll.add(123);
        coll.add(456);
        coll.add(new String("tom"));
        coll.add(false);
        coll.add(new Person("Jerry",20));
        coll.add(123);

        Collection coll1 = Arrays.asList(123,4567);
//        boolean remove = coll.remove(123);
        coll.removeAll(coll1);
//        coll.removeIf(123);
        System.out.println(coll);
//        System.out.println(remove);

    }

    @Test
    public void test3(){
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new Person("Jerry",20));
        coll.add(new String("Tom"));
        coll.add(false);



        //5.retainAll(Collection coll1):交集：获取当前集合和coll1集合的交集，并返回给当前集合
//        Collection coll1 = Arrays.asList(123,456,789);
//        boolean b = coll.retainAll(coll1);
//        System.out.println(coll);
//        System.out.println(b);
//

        //equals(Object obj):
        Collection coll1 = new ArrayList();
        coll1.add(123);
        coll1.add(456);
        coll1.add(new Person("Jerry",20));
        coll1.add(new String("Tom"));
        coll1.add(false);

        boolean equals = coll.equals(coll1);
        System.out.println(equals);

    }

    @Test
    public void test4(){
        Collection coll = new ArrayList();
        coll.add(123);
        coll.add(456);
        coll.add(new Person("Jerry",20));
        coll.add(new String("Tom"));
        coll.add(false);

        System.out.println(coll.hashCode());


        Object[] objects = coll.toArray();
        for (int i = 0; i < objects.length; i++) {
            System.out.println(objects[i]);
        }


        List<String> strings = Arrays.asList(new String[]{"AA", "BB", "CC"});

        System.out.println(strings);

        List ints = Arrays.asList(123,456);

        System.out.println(ints);

        List int2 = Arrays.asList(new Integer[]{123,456});
        System.out.println(int2.size());
        System.out.println(int2);

        //iterator():


    }
}
